﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NFramework.DataAccess;

namespace NFramework.UnitTests.DataAccessTests
{
    [TestClass]
    public class DataAccessContextTests : Global
    {
        [TestMethod]
        public void PushSQLReturnsSQLConnectionOnGetConnection()
        {
            using (DataAccessContext.PushSQL(ConnectionString))
            {
                Assert.IsInstanceOfType(DataAccessContext.Current.GetConnection(), typeof(System.Data.SqlClient.SqlConnection));
            }
        }

        [TestMethod]
        public void PushOdbcReturnsOdbcConnectionOnGetConnection()
        {
            using (DataAccessContext.PushOdbc(ConnectionString))
            {
                Assert.IsInstanceOfType(DataAccessContext.Current.GetConnection(), typeof(System.Data.Odbc.OdbcConnection));
            }
        }

        [TestMethod]
        public void PushRepeatedlyRetainsCorrectStackOrderForConnectionTypes()
        {
            using (DataAccessContext.PushSQL(ConnectionString))
            {
                using (DataAccessContext.PushOdbc(ConnectionString))
                {
                    using (DataAccessContext.PushSQL(ConnectionString))
                    {
                        Assert.IsInstanceOfType(DataAccessContext.Current.GetConnection(), typeof(System.Data.SqlClient.SqlConnection));
                    }
                    Assert.IsInstanceOfType(DataAccessContext.Current.GetConnection(), typeof(System.Data.Odbc.OdbcConnection));
                }
                Assert.IsInstanceOfType(DataAccessContext.Current.GetConnection(), typeof(System.Data.SqlClient.SqlConnection));
            }
        }
    }
}
